package com.itheima.Test01;

import com.itheima.bean.Card;
import com.itheima.onetoone.CardMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class OneToOneTest {
    InputStream is;
    SqlSession sqlSession =null;
    CardMapper cardMapper= null;

    {
        try {
            is = Resources.getResourceAsStream("OneToOne.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
            sqlSession = sqlSessionFactory.openSession(true);
            cardMapper = sqlSession.getMapper(CardMapper.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void selectAll() throws IOException {
        List<Card> cards = cardMapper.selectAll();
        for (Card card:cards) {
            System.out.println(card);
        }
        sqlSession.close();
        is.close();
    }
}
